from django.db import models
from datetime import datetime, timedelta
from django.contrib.auth.models import User
from django.db.models.query import QuerySet
def today():
	now = datetime.now()
	start = datetime.min.replace(year=now.year, month=now.month, day=now.day)
	end = (start + timedelta(days=1)) - timedelta.resolution
	return (start, end)
	
class Post(models.Model):
	title = models.CharField(max_length=100, help_text='Post Title')
	content = models.TextField()
	creation_date = models.DateTimeField(default=datetime.now())
	creator = models.ForeignKey(User, related_name='post_creator_set')
	comments_allowed = models.BooleanField(default=True, help_text='Comments allowed?')
	def __unicode__(self):
		return self.title
	def get_absolute_url(self):
		slug = self.title.replace(' ', '-').lower()
		return "/blog/%i/%i/%i/%i/" % (self.creation_date.year, self.creation_date.month, self.creation_date.day, self.id)


class Comment(models.Model):
	post = models.ForeignKey(Post)
	name = models.CharField(max_length=100)
	email = models.EmailField()
	content = models.TextField()
	creation_date = models.DateTimeField(default=datetime.now())
	def __unicode__(self):
		return self.name
		
